# —*—coding:utf-8 -*-
# @Time        :2022/7/15 20:50
# @Author      :dhx
# @File        :login_page.py
# @Software: PyCharm
from selenium.webdriver.common.by import By
from pages.base_pageage import BasePage
from config.config import HOST1

finance_locator = (By.XPATH, '/html/body/div[1]/div/div/div[2]/ul[1]/li[8]/a')  # 定位财务


class LoginPage(BasePage):
    """登录页面类"""
    url = 'http://192.168.3.133/crm'
    username_locator = (By.NAME, 'name')
    password_locator = (By.NAME, 'password')
    login_btn_locator = (By.NAME, 'submit')
    yibaio_locator = (By.XPATH, '/html/body/div[5]/div[1]/ul/li[2]/a')
    finance_locator = (By.XPATH, '/html/body/div[1]/div/div/div[2]/ul[1]/li[8]/a')  # 定位财务

    def input_username(self, username):
        """输入用户名"""
        self.driver.find_element(*self.username_locator).send_keys(username)

    def input_password(self, password):
        """输入密码"""
        self.driver.find_element(*self.password_locator).send_keys(password)

    def click_login(self):
        """点击登录"""
        self.driver.find_element(*self.login_btn_locator).click()

    def login_crm(self, username, password):
        """登录crm"""
        element = BasePage(self.driver)
        element.find(self.username_locator).send_keys(username)
        element.find(self.password_locator).send_keys(password)
        element.find(self.login_btn_locator).click()

    def switch_goods_page(self, url):
        """在首页切换到产品页"""
        self.driver.get(url)

    def yibiaopan(self):
        """仪表盘"""
        self.driver.find_element(*self.yibaio_locator).click()

    def fince(self):
        """点击财务"""
        self.driver.find_element(*self.finance_locator).click()
